#-*- coding:utf-8 -*-
from PIL import Image
import os
 
 
"""
    将一张GIF动图分解到指定文件夹
    src_path：要分解的gif的路径
    dest_path：保存后的gif路径
"""
NO_SIZE = 5

def nameImg(index:int,size=NO_SIZE):
    index_str = str(index)
    index_size = len(index_str)
    divide = size-index_size
    if divide > 0:
        return '0'*divide+index_str
    else :
        return index_str

def gifSplit(src_path, dest_path, suffix="png"):
    img = Image.open(src_path)
    for i in range(img.n_frames):
        img.seek(i)
        new = Image.new("RGBA", img.size)
        new.paste(img)
        new.save(os.path.join(dest_path, "%s.%s" %(nameImg(i), suffix)))

if __name__ == '__main__':
    gifSplit('3.gif','C:/E/temp/pic/')